const session = require("./session");
const decrypt = require("./decrypt");
const station_names = require("./station-names");

async function main() {
  const resp = await session.getJson(
    "https://kyfw.12306.cn/otn/leftTicket/query",
    {
      "leftTicketDTO.train_date": "2023-10-22",
      "leftTicketDTO.from_station": "ALY",
      "leftTicketDTO.to_station": "XAY",
      purpose_codes: "ADULT",
    }
  );

  if (!resp.status) return false;

  if (
    resp.data == null ||
    resp.data.length == 0 ||
    (resp.data.result && resp.data.result.length == 0)
  ) {
    return false;
  }

  let data;
  if (resp.data.flag == 1) {
    data = decrypt.cC(resp.data.result, resp.data.map);
  }

  trainListForIE = [];
  for (let i = 0; i < data.length; i++) {
    trainListForIE.push(
      data[i].queryLeftNewDTO.station_train_code +
        "(" +
        data[i].queryLeftNewDTO.start_time +
        "--" +
        data[i].queryLeftNewDTO.arrive_time +
        ")"
    );
  }

  console.log(1);
}

main();
